import axios from "axios";
import { addUrlPerFix } from "@/basa/utils/index";

const user = {
  state: {
    userDetal: {},
    accessToken: "",
    appToken: "",
    getUserInfo: {}
  },

  mutations: {
    SET_ACCESS_TOKEN: (state, token) => {
      state.accessToken = token;
    },
    SET_APP_TOKEN: (state, token) => {
      state.appToken = token;
    },
    SET_USER_DETAL: (state, obj) => {
      state.userDetal = obj;
    },
    SET_USER_ID: (state, userId) => {
      state.userId = userId;
    },
    SET_USER_NAME: (state, val) => {
      // localStorage.setItem('getUserInfo', JSON.stringify(val))
      state.getUserInfo = val;
    }
  },

  actions: {
    GetUserInfo({ commit }) {
      axios
        .post(
          addUrlPerFix(process.env.VUE_APP_BASEP_URL) +
            "/apis/basap/getUserInfo",
          {}
        )
        .then(res => {
          commit("SET_USER_NAME", res.data.data.userInfo);
        });
    }
  }
};

export default user;
